package org.skipper.samples.redission.sortset;

import org.redisson.api.RedissonClient;
import org.skipper.samples.redission.enums.RedisKeyEnum;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author shoujian
 * Date: 2021-08-27
 * Time: 下午6:11
 */
@Component
public class SortSetSource {

    @Resource
    @Qualifier(value = "redis-cloud_0")
    private RedissonClient redissonClient;

    public void zadd() {
        redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).add(1.1, 1.1);
    }

    public void zcard() {
        int count = redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).size();
        System.out.println("count = " + count);
    }

    public void zcount() {
        //测试了解
        redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).count(1.1, true, 1.1, false);
    }

    public void zincrby() {
        redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).addScore(1.1, 2);
    }

    public void zlexcount() {
        //测试了解
        redissonClient.getLexSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).countHead("test", true);
        redissonClient.getLexSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).countTail("test", false);
    }

    public void zrange() {
        redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).valueRange(1, 1);
    }

    public void zrevrange() {
        redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).valueRangeReversed(1, 1);
    }

    public void zunionstore() {
        redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).union("test");
    }

    public void zinterstore() {
        redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).intersection("test");
    }

    public void zrangebylex() {
        redissonClient.getLexSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).range(1, 1);
        redissonClient.getLexSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).rangeHead("test", true);
        redissonClient.getLexSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).rangeTail("test", false);
    }

    public void zrangebyscore() {
        redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).valueRange(1, 1);
        redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).entryRange(1, 1);
    }

    public void zrank() {
        redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).rank("test");
    }

    public void zrem() {
        redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).remove("test");
//        redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).removeAll()
    }

    public void zremrangebylex() {
        redissonClient.getLexSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).removeRange("test", true, "test", false);
        redissonClient.getLexSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).removeRangeHead("test", true);
        redissonClient.getLexSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).removeRangeTail("test", false);
    }

    public void zremrangebyscore() {
        redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).removeRangeByScore(1.1, true, 1.1, false);
    }

    public void zrevrangebyscore() {
        redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).entryRangeReversed(1, 2);
        redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).valueRangeReversed(1, 2);
    }

    public void zrevrank() {
        redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).revRank(1);
    }

    public void zscore() {
        redissonClient.getScoredSortedSet(RedisKeyEnum.SORT_SET_TEST.getCode()).getScore(1);
    }


}
